package com.yanqu.road.server.cmd.activity.hsisland.cross;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.HsIslandProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.hsisland.HsIslandActivityModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = Protocol.S_HS_ISLAND_KILL_BOSS_DAMAGE_RANK_REWARD_FROM_CROSS,desc = "海神岛-跨服返回-领取boss榜单奖励")
public class HsIslandKillBossDamageRankRewardFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        HsIslandProto.HsIslandKillBossDamageRankRewardFromCrossMsg reqMsg = HsIslandProto.HsIslandKillBossDamageRankRewardFromCrossMsg.parseFrom(packet.getBytes());
        HsIslandProto.HsIslandKillBossDamageRankRewardRespMsg.Builder respMsg = HsIslandProto.HsIslandKillBossDamageRankRewardRespMsg.newBuilder();
        respMsg.setRet(reqMsg.getRet());
        if (reqMsg.getRet() == 0) {
            // 添加奖励

            String rewardStr = reqMsg.getReward();
            if (!StringUtils.isNullOrEmpty(rewardStr)) {
                Property reward = PropertyHelper.parseStringToProperty(rewardStr);
                //添加奖励
                player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.HsIsland, eLogMoneyType.HsIslandKillBossDamageRankReward);
            }
            respMsg.setReward(reqMsg.getReward());
            respMsg.addAllHadRewardBattleFieldIdList(reqMsg.getHadRewardBattleFieldIdListList());
        }
        player.sendPacket(ClientProtocol.U_HS_ISLAND_KILL_BOSS_DAMAGE_REWARD_REQ, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {}
}
